﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using pryConvertTXT.EF;

namespace pryConvertTXT.Clases_DAO
{
    class clsEmpresaClienteDAO
    {
        DataEntitiesSeguridad ContextoDeObjs = new DataEntitiesSeguridad();
        public bool Insertar(EmpresaCliente Obj)
        {
            try
            {
                ContextoDeObjs.AddToEmpresaCliente(Obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception ex)
            {
                //Interaction.MsgBox(ex.InnerException.Message, MsgBoxStyle.Critical);
                return false;
            }
            return true;
        }

        public bool Modificar(EmpresaCliente obj)
        {

            try
            {
                ContextoDeObjs.AttachTo("EmpresaCliente", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception ex)
            {
                //Interaction.MsgBox(ex.Message, MsgBoxStyle.Critical);
                return false;

            }
            return true;
        }

        public bool Eliminar(EmpresaCliente obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("EmpresaCliente", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception ex)
            {
                //Interaction.MsgBox(ex.Message, MsgBoxStyle.Critical);
                return false;
            }
            return true;
        }
        public List<EmpresaCliente> listar()
        {
            List<EmpresaCliente> lista = new List<EmpresaCliente>();
            var q = from c in ContextoDeObjs.EmpresaCliente
                    select c;

            lista = q.ToList();
            return lista;
        }
    }
}
